package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import Models.PurchaseOrderView;

public class PurchaseOrderViewPresenter extends AbstractPresenter<PurchaseOrderView> {
	final String SINGLEITEM = "purchaseOrderView";
	final String MULTIITEM = "purchaseOrderViews";
	
	public ArrayList<PurchaseOrderView> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public PurchaseOrderView tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public PurchaseOrderView createItemFromJSONObject(JSONObject jsonObject){
		PurchaseOrderView item = new PurchaseOrderView();
		try{
			item.setExported(jsonObject.getBoolean("exported"));
			item.setPoDate(timeFormat.parse(jsonObject.getString("pODate")));
			item.setPoID(jsonObject.getInt("poid"));
			item.setPoState(jsonObject.getInt("pOState"));
			
			return item;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(PurchaseOrderView item){
		try{
			JSONObject json = new JSONObject();
			json.put("exported", item.isExported());
			json.put("pODate", getDate(item.getPoDate()));
			json.put("poid", item.getPoID());
			json.put("pOState", item.getPoState());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public PurchaseOrderView getEmptyEntity(){
		PurchaseOrderView entity = new PurchaseOrderView();
		return entity;
	}
}
